<!--
 * new page
 * @author: liuxin
 * @since: 2024-08-16
 * delete_admin.vue
-->
<template>
	<el-dialog v-model="dialogFormVisible" title='撤回申请' width="30%" center>
		<span>确定取消此产品的出库申请吗？</span>
		<template #footer>
			<span class="dialog-footer">
				<el-button type="primary" @click="withdrawProductFn">确定</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import { ref, onBeforeUnmount } from "vue"
import { bus } from "@/utils/mitt.js"
import { withdrawApplyProduct } from '@/api/product.js'
import { ElMessage } from 'element-plus'

const withdrawId = ref()
bus.on('withdrawId', (id: number) => {
	withdrawId.value = id
})
const emit = defineEmits(['success'])
// 删除产品
const withdrawProductFn = async () => {
	const res = await withdrawApplyProduct(withdrawId.value)
	// console.log(withdrawId.value);
	if (res.status == 0) {
		ElMessage({
			message: '撤回申请成功',
			type: 'success'
		})
		emit('success')
		dialogFormVisible.value = false
	} else {
		ElMessage.error('撤回申请失败')
		dialogFormVisible.value = false
	}
}


// 弹窗开关

const dialogFormVisible = ref(false)
// 打开编辑管理员弹窗
const open = () => {
	dialogFormVisible.value = true
}
defineExpose({
	open
})

// 取消订阅/监听
onBeforeUnmount(() => {
	bus.all.clear()
})
</script>

<style scoped lang="scss"></style>